package com.micangcaihang.micang.mvp.main.ui;

import android.os.Bundle;
import android.os.Handler;

import com.micangcaihang.common.base.activity.BaseActivity;
import com.micangcaihang.common.utils.StatusBarUtil;
import com.micangcaihang.micang.R;
import com.micangcaihang.micang.databinding.ActivitySplashBinding;
import com.micangcaihang.micang.entity.UserInfoSp;
import com.micangcaihang.micang.mvp.login.ui.LoginActivity;
import com.micangcaihang.micang.mvp.main.presenter.SplashPresenter;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/07/30
 *     update : 2017/07/30
 *     desc   : 欢迎页
 *     version: 1.0
 * </pre>
 */

public class SplashActivity extends BaseActivity<SplashPresenter, ActivitySplashBinding> {
    /**
     * 获取资源文件布局
     *
     * @return 资源布局文件layout
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    /**
     * 获取传递的bundle数据
     *
     * @param extras
     */
    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected void setStatusBar() {
        StatusBarUtil.setColor(this, getResources().getColor(R.color.splash_StatusBar), 0);
    }

    /**
     * 初始化按钮监听
     */
    @Override
    protected void initListener() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                DoActivity();
            }
        }, 3000);
    }

    private void DoActivity() {
        if (UserInfoSp.getInstance().isLogin()) {
            if (UserInfoSp.getInstance().getDepartment_id() == 18) {
                startActivity(FMainActivity.class);
            } else if (UserInfoSp.getInstance().getDepartment_id() == 19) {
                startActivity(DMainActivity.class);
            } else {
                startActivity(LoginActivity.class);
            }
            finish();
        } else {
            startActivity(LoginActivity.class);
            finish();
        }
    }
}
